package com.zyht.wechat.tplmsg;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.wx.core.process.WxApi;
import com.zyht.common.util.HttpUtils;
import com.zyht.wechat.inf.ITemplateMessageProcess;
import com.zyht.wechat.tplmsg.bean.BaseTpl;

public class DefaultTemplateMessageProcess implements ITemplateMessageProcess{

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Override
	public void doSendMessage(String accessToken, BaseTpl tpl) {
		String tempUrl = String.format(WxApi.SEND_TEMPLATE, accessToken);
		try{
			String json = JSON.toJSONString(tpl);
			if(logger.isInfoEnabled()){
				logger.info("请求发送模板消息报文是：\n" + json);
			}
			String resultStr = HttpUtils.post(tempUrl, json);
			if(logger.isInfoEnabled()){
				logger.info("发送模板消息结果是："+resultStr);
			}
		} catch (IOException e){
			e.printStackTrace();
		}
	}

}
